//	ID : pallab81
// 	PROG : 793
// 	LANG : C++
// 	2011-07-10-16.09.05 Sunday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define fo(i,ed) for(int i = 0 ; i < ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )


const int inf = (int)1e6+10;
int parent[ inf ],rank[ inf ];
int C;

inline void _SET() {
    fo(i,inf) {
        parent[i]=i;
        rank[i]=0;
    }
}
inline int _FIND(int now_node) {
    if( now_node!= parent[ now_node ] ) {
        parent[ now_node ] = _FIND( parent[ now_node ] );
    }
    return parent[ now_node ];
}
inline void _UNION(int node_x, int node_y) {
    int parent_x = parent[ node_x ];
    int parent_y = parent[ node_y ];
    if( rank [ parent_x ] > rank [ parent_y ] ) {
        parent[ parent_y ] = parent_x;
    } else {
        parent[ parent_x ] = parent_y;
    }
    if( rank[ parent_x ] == rank[ parent_y ] ) {
        rank[ parent_y ]+=1;
    }
}
inline void proc() {
        char input[100], tt[10];
        int i, a, b, parent_x, parent_y, n1 = 0, n2 = 0;
        while(gets(input)) {
                for(i = 0; input[i]; i++){
                        if(input[i] == '\n'){
                                input[i] = NULL;
                        }
                }
                if(strlen(input) == 0) break;
                sscanf(input,"%s%d%d",tt,&a,&b);
                parent_x = _FIND(a); parent_y = _FIND(b);
                if(!strcmp(tt,"q")) {
                        if( parent_x != parent_y) n2++;
                        else n1++;
                }
                else {
                        if(parent_x != parent_y){
                            _UNION(parent_x, parent_y);
                        }
                }
        }
        printf("%d,%d\n",n1,n2);
}


int main() {
        int cases;
        char input[100];
        gets(input);
        sscanf(input,"%d",&cases);
        gets(input);
        while(cases--) {
                gets(input);
                sscanf(input,"%d",&C);
                _SET();
                proc();
                if(cases) putchar('\n');
        }
return 0;
}
